<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul class="nav">
        <li>Cat</li>
        <li>Dog</li>
        <li>Man</li>
        <li>Women</li>
    </ul>

<script>
    var lis = document.querySelector('.nav').querySelectorAll('li');
    var li_index;
    for(li_index = 0;li_index < lis.length; li_index++){
        lis[li_index].index = li_index;//给li动态添加属性
    }
    console.log(lis[2].index);

    /* 利用闭包的方式得到当前li的索引号 */
    
</script>
</body>
</html>